<template>
	<view class="">
		<view class="conterLIstA">
			<view class="titletitle">
				<view>
					全国甩单总群 
				</view> 
			</view>
			<view class="sousokuang">
				<view class="sunsl">
					<input v-model="vModelvalue"  type="text" placeholder="搜索关键词">
					<view @click="sunslFunTeb" class="sousokuan">搜索</view>
				</view>
			</view>
		</view>
		<view class=""  style="padding: 0 24rpx;">
			<scroll-view
			:style="{height:scrollHeight}"
			:scroll-top="scrollTop"
			@scrolltoupper="loadHistory"
			scroll-y="true"
			>
				<view v-for="(item,index) in msgList.list">
					<chat-list  goPages="/pages/index/person" :my_data="my_data"  :type="item.msg.type" :list_id="list_id" :mes="item" :mesTime="timestampFormat(item.msg.time+'')+'  ('+item.msg.show_name+')'" :conter="item.msg.content.text"></chat-list>
				</view>
			</scroll-view>
		<!-- 	<chatList :type="1"></chatList>
			<chatList :type="2"></chatList>
			<view class="conteTitle">A海南财税小亮 邀请 微信用户NNLJ1 加入群聊</view>
			<chatList :conter="'这里是多行样式占位文字'"></chatList>
			<chatList :type="3" :conter="'这里是多行样式占位文字'"></chatList> -->
		</view>
		<logonIs v-if="!token" :referral_code="referral_code"></logonIs>
	</view>
</template>

<script>
	import chatList from "../../components/chatList/index.vue"
	import _action from '../../common/_action';
	import _data from '../../common/_data';
	import logonIs from "../../components/logon_is.vue"
	export default{
		components:{
			chatList,
			logonIs
		},
		data(){
			return {
				list_id:"",
				msgList:{
					list:[],
				},
				token:uni.getStorageSync('token'),
				referral_code:"",
				scrollHeight:"0px",
				vModelvalue:"",
				my_data:{},
				scrollTop:0,
			}
		},
		onLoad() {
			// this.scchatData();	
			let _this=this;
			_this.my_data = _data.data('user_info');
			this.getScrollContentHeight();
		},
		// onReachBottom(e) {
		// 	console.log(e);
		// 	this.scchatData(e);
		// },
		methods:{
			loadHistory(e){
				this.scchatData(e);
			},
			getScrollContentHeight(type = 'show',not_return = 1){
			  let _this = this;
			  let query = uni.createSelectorQuery();
				query.select('.conterLIstA').boundingClientRect();
			     uni.getSystemInfo({
			        success:function (res) {
			          console.log("windowHeight:",res.windowHeight);
			          // _this.scrollInfo.totall_height = res.windowHeight;
			          query.exec(data => {
						console.log(data)
						_this.scrollHeight=res.windowHeight-data[0].height-50+'px';
						_this.setTimeoutScrollTop(500);
									// _this.scrollHeight=(res.windowHeight-data[0].height-data[1].height)+'px';
			            // _this.autoHeight(type,not_return)
			          })
			        }
			     })
			},
			setTimeoutScrollTop(time){
				let _this=this;
				setTimeout(function () {
				  _this.$nextTick(function () {
				    _this.scrollTop =(new Date()).getTime()/8732;
				  });
				},time||0)
			},
			sunslFunTeb(){
				this.msgList={
					list:[],
				}
				this.scchatData();
				this.setTimeoutScrollTop(500);
			},
			timestampFormat (time) {
			  return _action.timestampFormat(time);
			},
			msgDataHandle (data, type) {
			  for (let i = 0, j = data.length, msg_img; i < j; i++) {
			    if (data[i].type == 0 && data[i].msg.type == 2) {
			      data[i].msg.content = this.setPicSize(data[i].msg.content);
			    } else if (data[i].type == 0 && data[i].msg.type == 0) {
							
			    }
			  }
			  return data;
			},
			setPicSize (content) {
						// console.log()
			  // 让图片最长边等于设置的最大长度，短边等比例缩小，图片控件真实改变，区别于aspectFit方式。
			  let maxW = uni.upx2px(350);//350是定义消息图片最大宽度
			  let maxH = uni.upx2px(350);//350是定义消息图片最大高度
						if(content.imgList&& content.imgList.length){
							content.imgList.map((item,index)=>{
								// console.log(item,index)
								if (item.w > maxW || item.h > maxH) {
								  let scale = item.w / item.h;
								  item.w = scale > 1 ? maxW : maxH * scale;
								  item.h = scale > 1 ? maxW / scale : maxH;
								  let url_array = item.url.split('.');
								  if (item.url.indexOf('_thumb.') == -1) {
								    item.url = url_array[0] + '_thumb.' + url_array[1];
								  }
								}
							})
						}else if (content.w > maxW || content.h > maxH) {
			    let scale = content.w / content.h;
			    content.w = scale > 1 ? maxW : maxH * scale;
			    content.h = scale > 1 ? maxW / scale : maxH;
			    let url_array = content.url.split('.');
			    if (content.url.indexOf('_thumb.') == -1) {
			      content.url = url_array[0] + '_thumb.' + url_array[1];
			    }
			  }
			  return content;
			},
			scchatData(){
				let _this=this;
				let time=_this.msgList.list;
				this.$httpSend({
				  path: '/im/get/scchatData',
				  data: {
					  keyword:_this.vModelvalue,
					  time:(time && time[0])?time[0].msg.time:0,
				  },
				  success_action: true,
				  success (res) {
					  // let list=_this.msgList.list;
					  let tebLIst=_this.msgDataHandle(res.data.list);
				    _this.msgList={
						...res.data,
						list:[...tebLIst,..._this.msgList.list]
					};
				  }
				});
			},
			
			// https://im.numtwin.com/im/get/scchatData
		}
	}
</script>

<style>
	.conteTitle{
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #9298A0;
		line-height: 36rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
		margin-bottom: 32rpx;
	}
	.titletitle{
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #181D24;
		line-height: 36rpx;
		padding: 24rpx 0;
		display: flex;
		justify-content: center;
		font-style: normal;
		text-transform: none;
	}
	.sousokuang{
		border-bottom: 1rpx solid #DCE1E8;
		margin-bottom: 24rpx;
		box-sizing: border-box;
		padding: 0 24rpx;
	}
	.sunsl{
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 28rpx;
		height: 72rpx;
		margin-bottom: 24rpx;
		padding-left: 24rpx;
		background: #F2F4F7;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}
	.sousokuan{
		width: 120rpx;
		text-align: center;
		line-height: 72rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		font-style: normal;
		text-transform: none;
		height: 72rpx;
		background: #256FF3;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}
</style>